<template>
  <div>
    <!-- 头部栏 -->
    <el-container>
      <el-header class="headhome">
        <div class="title">云e办</div>
        <el-dropdown class="userInfo" @command="commandHanderl">
          <span class="el-dropdown-link">
            {{ userNew.name }}<i><img src="../../public/aaa.jpg" /></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="self">个人中心</el-dropdown-item>
            <el-dropdown-item command="config">设置</el-dropdown-item>
            <el-dropdown-item command="outlogin">注销登录</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-header>
      <el-container>
        <!-- 左侧栏 -->
        <el-aside width="200px">
          <!-- 导航栏 -->
          <el-menu router v-for="(item, index) in routes" :key="index">
            <el-submenu :index="index + ''" v-if="!item.hiddens">
              <template slot="title"
                ><i
                  :class="item.iconCls"
                  style="color: #1accff; margin-right: 5px"
                ></i>
                <span>{{ item.name }}</span></template
              >
              <el-menu-item
                :index="children.path"
                v-for="(children, index) in item.children"
                :key="index"
                >{{ children.name }}</el-menu-item
              >
            </el-submenu>
          </el-menu>
        </el-aside>
        <!-- 中部栏 -->
        <el-main>
          <el-breadcrumb
            separator-class="el-icon-arrow-right"
            v-if="this.$router.currentRoute.path != '/home'"
          >
            <el-breadcrumb-item :to="{ path: '/home' }"
              >首页</el-breadcrumb-item
            >
            <el-breadcrumb-item>{{
              this.$router.currentRoute.name
            }}</el-breadcrumb-item>
          </el-breadcrumb>
          <div v-if="this.$router.currentRoute.path == '/home'" class="homeTitle">
            欢迎来到云E办
          </div>
          <router-view class="HomeRouterView"/>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: "Home",
  data() {
    return {};
  },
  methods: {
    commandHanderl(command) {
      if (command == "outlogin") {
        this.$confirm("确定要退出吗", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            //注销登录
            this.postRequest("/logout");
            window.sessionStorage.removeItem("token");
            this.$store.commit("initRoutes", []);
            this.$router.replace("/");
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "取消退出",
            });
          });
      }
    },
  },
  computed: {
    routes() {
      return this.$store.state.routes;
    },
    userNew() {
      return this.$store.state.userValue;
    },
  }
};
</script>

<style scoped>
.headhome {
  display: flex;
  background-color: cornflowerblue;
  justify-content: space-between;
  align-items: center;
}
.title {
  font-size: 30px;
  font-style: 华文楷体;
  color: white;
}
.el-dropdown-link img {
  width: 45px;
  height: 45px;
  border-radius: 24px;
  margin-left: 8px;
}
.headhome .userInfo {
  cursor: pointer;
}
.homeTitle{
  font-family: 华文楷体;
  text-align: center;
   font-size: 40px;
   color: #409eff;
   padding-top: 50px;
}
.HomeRouterView{
  margin-top: 10px;
}
</style>
